<?php
namespace Taxx\UserBundle\Forms;

use Taxx\KernelBundle\Model\FormBuilder\FormBuilder;
use Taxx\KernelBundle\Model\Utils\JsonTranslator;
use Taxx\KernelBundle\Model\Utils\PublicFileRegistry;
use Doctrine\ORM\EntityManager;
use Taxx\KernelBundle\Entity\User;

class EditProfileForm 
{
    private $builder;
    
    public function __construct(EntityManager $em, User $user, $language) 
    {
        $translations = JsonTranslator::parseTranslationFile(PublicFileRegistry::getFilePath("user_translations"));
        $labels = $translations['form_labels'][$language];
        
        
        $this->builder = new FormBuilder();
        $this->builder->setLegend($labels['edit_profile']);
        
        $this->builder->addInputField('edit_profile_email', $labels['email'], array('name'=>'email', 'type' => 'text', 'value' => $user->getEmail()));
        $this->builder->addInputField('edit_profile_old_password', $labels['old_password'], array('name'=>'old_password', 'type' => 'password'));
        $this->builder->addInputField('edit_profile_new_password', $labels['new_password'], array('name'=>'new_password', 'type' => 'password'));
        $this->builder->addInputField('edit_profile_confirm_password', $labels['confirm_password'], array('name'=>'confirm_password', 'type' => 'password'));
        $language_entities = $em->getRepository('TaxxKernelBundle:Language')->findAll();
        $languages = array();
        foreach($language_entities as $le)
            $languages[''.$le->getId()] = $le->getName();
        $this->builder->addSelectField('edit_profile_language', $labels['language'], $languages, $user->getLanguage()->getId(), array('name'=>'language'));
        $this->builder->addButton('edit_profile_btn', $labels['send_btn'], array('type'=>'button', 'onclick'=>'checkEditProfileForm(\''.$language.'\')'));
    }
    
    public function getForm($action)
    {
        return $this->builder->getForm('editProfileForm', array('action'=>$action, 'method'=>'post'));
    }
}

?>
